/**
 * Created by pro on 2018/7/30.
 */
$(function(){
    sendAjax('/v1/regions.json', 'get', {}, function(json) {
        var regions = json.body.rows;
        sendAjax('/v1/standards.json', 'get', {}, function(json) {
            var standards = json.body.rows;
            sendAjax('/v1/manager/apart/detail.json', 'get', {id:id}, function(json){
                var data = json.body.data;
                if (data) {
                    $('.apart-name').text(data.name);
                    $.each(regions, function(n,v) {
                        if (v.id == data.region) {
                            $('.apart-region').text(v.name);
                        }
                    });
                    switch (data.type) {
                        case 1: $('.apart-type').text('一居室');break;
                        case 2: $('.apart-type').text('一室一厅');break;
                        case 3: $('.apart-type').text('两室一厅');break;
                        case 4: $('.apart-type').text('三室一厅');break;
                        case 5: $('.apart-type').text('三室两厅');break;
                        default : $('.apart-type').text('一居室');break;
                    }
                    $('.apart-address').text(data.address);
                    $('.apart-area').text(data.area + '平方米');
                    $.each(standards, function(n,v) {
                        if (v.id == data.standard) {
                            $('.apart-standard').text(v.name);
                        }
                    });
                    switch (data.orientations) {
                        case 1: $('.apart-orientations').text('朝东');break;
                        case 2: $('.apart-orientations').text('朝南');break;
                        case 3: $('.apart-orientations').text('朝西');break;
                        case 4: $('.apart-orientations').text('朝北');break;
                        default : $('.apart-orientations').text('朝东');break;
                    }
                    $('.apart-rent').text(data.rent);
                    $('.apart-other').text(data.other);
                    $('.apart-status').text(getStatus(data.status, data.is_program));
                }
            });
        });
    });
});

function getStatus(status, is_program) {
    var back = '';
    switch (status) {
        case 1 : back = '未开放';break;
        case 2 : back = '已开放';break;
        case 3 : back = '租用中';break;
        case 4 : back = '维修中';break;
        default : back = '未开放';break;
    }
    if (status == 2 && is_program == 1) {
        back = '项目中';
    }
    return back;
}